About

In the United States, the people do not directly vote for President. The Founding Fathers believed that a true democracy was subject to the rule of factions and mob rule. The electoral college, they believed, would protect against this. Instead of having each person’s vote count towards President, each state receives a certain number of electoral votes. The number of electoral votes for each state is equal to the numbers of members of congress for that state (the number of senators, plus the number of representatives). When the 23rd Amendment was ratified in 1961, Washington D.C. was also given electoral votes, but not to exceed the lowest number of votes that a state has – this has usually limited D.C. to 3 votes.

The data for the United States general elections was found from a Github repository which included multiple government datasets. Elections that were contested were labelled with asterisks in this dataset, so I ammended the dataset with the wikipedia data set found here: https://en.wikipedia.org/wiki/United_States_Electoral_College. The population data for the states are based off of the United States Census, conducted every 10 years. This dataset was found from a GitHub repository with historical data.

10 States with the Most Electoral Votes in 2016

state_function <- function(input){
  state_pop_estimated <- state_populations %>%
    filter(state == input) %>%
    select(year, population, state) %>%
    approx(xout = round(min(state_populations$year), digits = 3):2016, method = "linear", rule = 2) %>% #round(min(state_populations$year), digits = 3)
    as.data.frame() %>%
    mutate(year = x, population = round(y, 0)) %>%
    select(year, population)
  
  state_electoral_votes <- electoral_votes %>%
    filter(state == input)
  
  inner_join(state_pop_estimated, state_electoral_votes, by = "year")
}
n <- unique(elections$state)[-51]
n <- as.character(n)
typeof(n)
## [1] "character"
state_dfs <- map(n, state_function)

complete_df <- bind_rows(state_dfs)

## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

recent_years <- complete_data_frame %>%
  filter(year >= 1932)

rep_model <- lm(data = recent_years, formula = ev_density ~ Rep * year)
year_df <- data.frame(Rep = rep(1, 85), year = 1932:2016)
year_df$predicted_value <- as.numeric(predict.lm(rep_model, year_df))

year_df_dem <- data.frame(Rep = rep(0, 85), year = 1932:2016)
year_df$predicted_value_dem <- as.numeric(predict.lm(rep_model, year_df_dem))
ggplot(year_df) +
  geom_point(aes(x = year, y = predicted_value),  color = "red") +
  geom_point(aes(x = year, y = predicted_value_dem), color = "blue")